package com.crm.controller;

import com.crm.domain.DataGridView;
import com.crm.service.ServiceMangerService;
import com.crm.util.ResultDto;
import com.crm.vo.ServiceVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
public class ServiceController extends BaseController2{
    private Logger logger= LoggerFactory.getLogger(this.getClass());
    @Autowired
   private ServiceMangerService serviceMangerService;
    @GetMapping(value = "/services.do")
    public DataGridView getServiceDistribute(ServiceVo serviceVo){
        return serviceMangerService.getServiceListByPage(serviceVo);
    }
    @PostMapping(value = "/service/insertservice.do",produces = "application/json;charset=UTF-8")
    public ResultDto insertService(ServiceVo serviceVo){
        ResultDto dto=new ResultDto();
        boolean flag=this.serviceMangerService.addService(serviceVo);
        if(flag) {
            dto.setCode(200);
            dto.setMsg("添加成功");
        }
        return dto;
    }
    //删除
    @GetMapping(value = "/service/deleteService.do")
    public ResultDto deleteService(Integer id){
        ResultDto dto=new ResultDto();
        try {
            this.serviceMangerService.removeService(id);
            dto.setCode(200);
            dto.setMsg("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            dto.setCode(-1);
            dto.setMsg("删除成功");
        }
        return dto;
    }
    //批量删除
    @RequestMapping(value = "/service/deleteBatchService.do")
    @ResponseBody
    public ResultDto deleteBatchService(@RequestParam("ids[]")Integer[] ids){
        ResultDto dto=new ResultDto();
        try {
            this.serviceMangerService.removeBatchService(ids);
            dto.setCode(200);
            dto.setMsg("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            dto.setCode(-1);
            dto.setMsg("删除失败");
        }
        return dto;
    }
    @PostMapping(value = "/service/updatAssagn.do",produces = "application/json;charset=UTF-8")
    public ResultDto updatAssagn(int id, String assignee, Date distributeTime){
        ResultDto dto=new ResultDto();
        boolean flag=this.serviceMangerService.addAssagn(id,assignee,distributeTime);
        logger.debug("***************************");
        logger.debug(distributeTime+"");
        if(flag) {
            dto.setCode(200);
            dto.setMsg("分配成功");
        }
        return dto;
    }
    @PostMapping(value = "/service/updatDeal.do",produces = "application/json;charset=UTF-8")
    public ResultDto updatDeal(int id,String serviceDeal,String conductor,Date dealTime){
        ResultDto dto=new ResultDto();
        boolean flag=this.serviceMangerService.addDeal(id,serviceDeal,conductor,dealTime);
        if(flag) {
            dto.setCode(200);
            dto.setMsg("处理成功");
        }
        return dto;
    }
    @PostMapping(value = "/service/updatResponse.do",produces = "application/json;charset=UTF-8")
    public ResultDto updatResponse(int id,String dealResrult,String satisfaction){
        ResultDto dto=new ResultDto();
        boolean flag=this.serviceMangerService.addResponse(id,dealResrult,satisfaction);
        if(flag) {
            dto.setCode(200);
            dto.setMsg("处理成功");
        }
        return dto;
    }
}
